package com.easyoffer.model.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.easyoffer.model.entity.Question;
import lombok.Data;

import java.util.List;

@Data
public class QuestionVO {
    /**
     * id
     */
    private Long id;

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
     * 标签列表（json 数组）
     */
    private List<String> tags;

    /**
     * 推荐答案
     */
    private String answer;

    /**
     * 创建用户 id
     */
    private Long userId;

    /**
     * 优先级
     */
    private Integer priority;

    /**
     * 浏览量
     */
    private Integer viewNum;

    /**
     * 点赞数
     */
    private Integer thumbNum;

    /**
     * 收藏数
     */
    private Integer favoriteNum;

    /**
     * 是否仅会员会员可见(0 不需要,1 需要)
     */
    private Integer needVip;

    public static Question voToEntity(QuestionVO questionVO) {
        Question question = new Question();
        BeanUtil.copyProperties(questionVO, question);
        String jsonStr = JSONUtil.toJsonStr(questionVO.getTags());
        question.setTags(jsonStr);
        return question;
    }
    public static QuestionVO entityToVo(Question question) {
        QuestionVO questionVO = new QuestionVO();
        BeanUtil.copyProperties(question, questionVO);
        questionVO.setTags(JSONUtil.toList(question.getTags(), String.class));
        return questionVO;
    }
}
